package cn.phecda.boot.data.jpa.support;

import cn.phecda.boot.common.lang.model.BaseEntity;
import cn.phecda.boot.data.core.exception.EntityNotFoundException;
import org.springframework.lang.NonNull;

import java.io.Serializable;

/**
 * <p> 基础服务 </p>
 *
 * @author : wanpinwei
 */
public interface CommonJpaService<R extends CommonJpaRepository<E, ID>, E extends BaseEntity, ID extends Serializable> {
    R getBaseRepository();

    @NonNull
    default E findById(@NonNull ID id) {
        return getBaseRepository().findById(id).orElseThrow(() -> new EntityNotFoundException(id));
    }
}
